<?php
/**
 * GPA Description
 * @package 
 * @name login
 * @filesource login.php
 * @author Meta Sanjaya
 */

$username = $_POST['wgt_user_username'];
$password = $_POST['wgt_user_password'];

$result = mysql_query("SELECT * FROM `".TABLE_PREFIX."users` WHERE `username`='$username' AND `pwd`='$password'", $MYSQL);
$users = mysql_fetch_assoc($result);
mysql_free_result($result);

$return = array();

if(count($users)) {
    if(!$users['active']) {
        $return['result'] = false;
        $return['message'] = "maaf, status anda sedang tidak aktif!";
    } else {
        unset($users['active']);
        $_SESSION['users'] = $users;
        $return['result'] = true;
        $return['message'] = "";
    }    
} else {
    $return['result'] = false;
    $return['message'] = "id pengguna dan kata sandi tidak cocok atau anda belum terdaftar!";
}

header('content-type: text/json');
die(json_encode($return));

?>
